#-*-coding:utf-8-*-#

import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gpd
from shapely.geometry import Point, Polygon


currentPath = os.getcwd()
wfindex = pd.DataFrame()
raw = pd.read_csv('Data_Fig1c_2.csv') # Wildfire index data
raw.columns = ['latitude','longitude','brightness','scan','track','acq_date',
               'acq_time','satellite','instrument','confidence','version',
               'bright_t31','frp','daynight','type']

wfindex = pd.concat([wfindex,raw])
wfindex = wfindex[(wfindex['latitude']<=50)&(wfindex['longitude']>=-126)]
wfindex = wfindex[wfindex['type'] == 0]
wfindex = wfindex[wfindex['confidence'] >= 95]
wfindex = wfindex.reset_index(drop=True)

geometry = gpd.points_from_xy(wfindex['longitude'],wfindex['latitude'])

# Unzip Data_Fig1b_1 shape file of US states

usmap = gpd.read_file('tl_2017_us_state.shp')
usmap = usmap[~usmap.STUSPS.isin(['HI','AK'])]
usmap = usmap.to_crs("EPSG:2163")

"""


month


"""

colors = ['gold','orange','darksalmon','IndianRed','red']

mt = ['March','April','May','June','July']

fig, ax = plt.subplots(figsize=(15, 15), dpi=400)
ax.axis('off')

for i in range(3,8):
    month = wfindex[wfindex['acq_date'].str.contains('2012-0'+str(i))]
    geometry = gpd.points_from_xy(month['longitude'],month['latitude'])
    geo_df = gpd.GeoDataFrame(month,crs='EPSG:4326',geometry=geometry)
    geo_proj = geo_df.copy()
    geo_proj['geometry']= geo_proj['geometry'].to_crs(epsg=2163)
    geo_proj[geo_proj['type'] == 0].plot(ax=ax, markersize=50,color='red',marker='o',
                                     label=mt[i-3],alpha= 0.8)

usmap.boundary.plot(ax=ax, color='black')
minx, miny, maxx, maxy = geo_proj.total_bounds
ax.set_xlim(minx-10**(5)*5, maxx+10**(5)*6)
ax.set_ylim(miny-10**(5)*5, maxy+10**(5)*6)
plt.legend(loc='lower left')
plt.savefig('Figure1d.png')


